<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="隧道编号" prop="field1">
        <el-input
          v-model="queryParams.field1"
          placeholder="请输入隧道编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="隧道名称" prop="field2">
        <el-input
          v-model="queryParams.field2"
          placeholder="请输入隧道名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:qitasheshibaoyangweihu:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          v-if="false"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:qitasheshibaoyangweihu:edit']"
          >编辑/查看</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          v-if="false"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:qitasheshibaoyangweihu:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          v-if="false"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:qitasheshibaoyangweihu:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="qitasheshibaoyangweihuList"
      :default-sort="{prop: 'id', order:'ascending'}"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="隧道编号" align="center" prop="field1" />
      <el-table-column label="隧道名称" align="center" prop="field2" />
      <el-table-column label="管养单位" align="center" prop="field3" />
      <el-table-column label="天气" align="center" prop="field6" />
      <el-table-column label="上次保养日期" align="center" prop="field7" />
      <el-table-column label="本次保养日期" align="center" prop="field8" />
      <el-table-column label="技术状况分类" align="center" prop="field14" />
      <el-table-column label="分项设施" align="center" prop="field11" />

      <el-table-column label="养护状态" align="center" prop="field10" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:qitasheshibaoyangweihu:edit']"
            >编辑/查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:qitasheshibaoyangweihu:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或编辑/查看其他设施保养维护对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="隧道名称" prop="field2">
          <el-select v-model="form.field2" placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field2 + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="隧道编号" prop="field1">
          <el-select v-model="form.field1" placeholder="请选择隧道编码">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field1 + ''"
              :label="dict.field1"
              :value="dict.field1 + ''"
              v-if="dict.field2 == form.field2"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="管养单位" prop="field3">
          <el-input v-model="form.field3" placeholder="请输入管养单位" />
        </el-form-item>
        <el-form-item label="天气" prop="field6">
          <el-input v-model="form.field6" placeholder="请输入天气" />
        </el-form-item>
        <el-form-item label="上次保养日期" prop="field7">
          <el-date-picker
            clearable
            size="small"
            v-model="form.field7"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择上次检查日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本次保养日期" prop="field8">
          <el-date-picker
            clearable
            size="small"
            v-model="form.field8"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择上次检查日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-divider></el-divider>

        <el-form-item label="检查类型" prop="field15">
          <el-select v-model="form.field15" placeholder="请选择检查类型">
            <el-option label="经常检查" value="经常检查"></el-option>
            <el-option label="定期检查" value="定期检查"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检查编码" prop="field13">
          <el-input v-model="form.field13" placeholder="请输入检查编码" />
        </el-form-item>

        <el-form-item label="技术状况分类" prop="field14">
          <el-select v-model="form.field14" placeholder="请选择技术状况分类">
            <el-option
              v-for="dict in qitasheshijishupingdingList"
              :key="dict.field9 + ''"
              :label="dict.field9"
              :value="dict.field9 + ''"
              v-if="dict.field11 == form.field13  && dict.field12 ==form.field15"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="分项设施" prop="field11">
          <el-select
            v-model="form.field11"
            placeholder="请选择分项设施"
            allow-create
            filterable
            default-first-option
          >
            <el-option label="电缆沟" value="电缆沟"></el-option>
            <el-option label="设备洞室" value="设备洞室"></el-option>
            <el-option label="洞外联络通道" value="洞外联络通道"></el-option>
            <el-option label="洞口限高门架" value="洞口限高门架"></el-option>
            <el-option label="洞口绿化" value="洞口绿化"></el-option>
            <el-option label="消音设施" value="消音设施"></el-option>
            <el-option label="减光设施" value="减光设施"></el-option>
            <el-option label="污水处理设施" value="污水处理设施"></el-option>
            <el-option label="洞口雕塑、隧道铭牌" value="洞口雕塑、隧道铭牌"></el-option>
            <el-option label="房屋设施" value="房屋设施"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="养护措施" prop="field12">
          <el-input v-model="form.field12" placeholder="请输入养护措施" />
        </el-form-item>



        <el-form-item label="养护人员" prop="field9">
          <el-input v-model="form.field9" placeholder="请输入养护人员" />
        </el-form-item>
        <el-form-item label="养护状态" prop="field10">
          <el-select
            v-model="form.field10"
            placeholder="请选择养护状态"
            allow-create
            filterable
            default-first-option
          >
            <el-option label="还未养护" value="还未养护"></el-option>
            <el-option label="正在养护" value="正在养护"></el-option>
            <el-option label="养护完成" value="养护完成"></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listQitasheshibaoyangweihu,
  getQitasheshibaoyangweihu,
  delQitasheshibaoyangweihu,
  addQitasheshibaoyangweihu,
  updateQitasheshibaoyangweihu,
  exportQitasheshibaoyangweihu,
} from "@/api/biz/qitasheshibaoyangweihu";
import { listSuidao } from "@/api/biz/suidao";
import { listQitasheshijishupingding} from '@/api/biz/qitasheshijishupingding'

export default {
  name: "Qitasheshibaoyangweihu",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      suidaoList: [],
      qitasheshijishupingdingList:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 其他设施保养维护表格数据
      qitasheshibaoyangweihuList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
        field7: null,
        field8: null,
        field9: null,
        field10: null,
        field11: null,
        field12: null,
        field13: null,
        field14: null,
        field15: null,
        field16: null,
        field17: null,
        field18: null,
        field19: null,
        field20: null,
        field21: null,
        field22: null,
        field23: null,
        field24: null,
        field25: null,
        field26: null,
        field27: null,
        field28: null,
        field29: null,
        field30: null,
        type: null,
        num: null,
        status: null,
        date1: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        field1: [
          { required: true, message: "隧道编号不能为空", trigger: "blur" },
        ],
        field2: [
          { required: true, message: "隧道名称不能为空", trigger: "blur" },
        ],
        field3: [
          { required: true, message: "管养单位不能为空", trigger: "blur" },
        ],
        field6: [
          { required: true, message: "天气不能为空", trigger: "blur" },
        ],
        field7: [
          { required: true, message: "上次保养日期不能为空", trigger: "blur" },
        ],
        field8: [
          { required: true, message: "本次检查日期不能为空", trigger: "blur" },
        ],
        field9: [
          { required: true, message: "养护人员不能为空", trigger: "blur" },
        ],
        field10: [
          { required: true, message: "养护状态不能为空", trigger: "blur" },
        ],
        field11: [
          { required: true, message: "分项设施不能为空", trigger: "blur" },
        ],
        field12: [
          { required: true, message: "养护措施不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
    listQitasheshijishupingding({}).then((response) => {
      this.qitasheshijishupingdingList = response.rows;
    });
  },
  methods: {
    /** 查询其他设施保养维护列表 */
    getList() {
      this.loading = true;
      listQitasheshibaoyangweihu(this.queryParams).then((response) => {
        this.qitasheshibaoyangweihuList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
        field7: null,
        field8: null,
        field9: null,
        field10: null,
        field11: null,
        field12: null,
        field13: null,
        field14: null,
        field15: null,
        field16: null,
        field17: null,
        field18: null,
        field19: null,
        field20: null,
        field21: null,
        field22: null,
        field23: null,
        field24: null,
        field25: null,
        field26: null,
        field27: null,
        field28: null,
        field29: null,
        field30: null,
        type: null,
        num: null,
        status: "0",
        date1: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加其他设施保养维护";
    },
    /** 编辑/查看按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getQitasheshibaoyangweihu(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "编辑/查看其他设施保养维护";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateQitasheshibaoyangweihu(this.form).then((response) => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQitasheshibaoyangweihu(this.form).then((response) => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delQitasheshibaoyangweihu(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有其他设施保养维护数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportQitasheshibaoyangweihu(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
